package com.information.manage.basic.audit.service.impl;

import com.information.manage.basic.audit.constant.AuditTypeEnum;
import com.information.manage.basic.audit.mapper.AuditTaskLevelMapper;
import com.information.manage.basic.audit.model.entity.AuditTaskDO;
import com.information.manage.basic.audit.service.AuditResultService;
import com.information.manage.dao.ManuMapper;
import com.information.manage.model.entity.ManuDO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@Slf4j
public class AuditResultServiceImpl implements AuditResultService {

    @Autowired
    private ManuMapper manuMapper;

    @Autowired
    private AuditTaskLevelMapper auditTaskLevelMapper;

    @Override
    public void handlePassAuditTaskAll(AuditTaskDO auditTaskDO) {
        handleAuditTaskAll(auditTaskDO);
    }


    private void handleAuditTaskAll(AuditTaskDO auditTaskDO){
        switch (AuditTypeEnum.valueOf(auditTaskDO.getType())){
            case OTHER:  // 人才培养
                ManuDO manuDO = manuMapper.selectById(Long.valueOf(auditTaskDO.getMainId()));
                manuDO.setAuditStatus(auditTaskDO.getStatus());
                manuDO.setUpdateTime(new Date());
                manuMapper.updateById(manuDO);
                break;
            default:
                break;
        }
    }

    @Override
    public void handlePassAuditTask(AuditTaskDO auditTaskDO) {
        handleAuditTaskAll(auditTaskDO);
    }

    @Override
    public void handleRejectAuditTaskAll(AuditTaskDO auditTaskDO) {
        handleAuditTaskAll(auditTaskDO);
    }
}
